<?php
namespace Home\Controller;
use Think\Controller;

class CommodityController extends Controller
{
	// 商品列表
	public function index()
	{
		$cid=I('get.cid');
		$data = M('Product_product_class');
		$image = M('Picture');
	// 查询满足要求的总记录数
		$count = $data->count();
	// 实例化分页类 传入总记录数和每页显示的记录数
		$Page = new \Think\Page($count, 20);
	// 分页显示输出	
		// $show = $Page->show(); 		
	// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $data->join('RIGHT JOIN product ON product_product_class.product_id = product.id')->order('id')->where('product_class_cid='.$cid)->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach ($list as $key => $value) {
			$list[$key]['images'] = $image->where('product_id='.$value['id'])->find();
		}

		$top = $data->join('RIGHT JOIN product ON product_product_class.product_id = product.id')->order('id')->where('product_class_cid='.$cid)->limit(0,7)->select();

		$this->assign('list', $list);
		$this->assign('top', $top);
	//  赋值分页输出	
		// $this->assign('page', $show); 	
	//  输出模板
		$this->display(); 
	}


	//  商品显示
	public function product()
	{
		$id=I('get.id');
		$data = M('Product');
		$image = M('Picture');

		$list = $data->join('picture ON product.id=picture.product_id')->limit(0,11)->select();
print_r($list);
		$this->assign('list',$list);
		$this->display();

	}


	

}